package com.learn.demo.bio;

import java.io.*;
import java.net.Socket;

public class BIOFileCopyDemoClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 6001);
        File file = new File("C:\\Users\\Ban&Deng\\Downloads\\QQPCDownload1652.exe");
        InputStream inputStream = new FileInputStream(file);
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        byte[] bytes = new byte[4096];
        int readCount = 0;
        int total = 0;
        long startTime = System.currentTimeMillis();
        while ((readCount = inputStream.read(bytes)) != -1) {
            total += readCount;
            dataOutputStream.write(bytes);
        }
        System.out.println(String.format("发送总字节%d,耗时%dms", total, System.currentTimeMillis() - startTime));
    }
}
